% From: http://www.ncbi.nlm.nih.gov/pubmed/15142845
% Title: Computer model of action potential of mouse ventricular myocytes
% Authors: Bondarenko, Szigeti, Bett, Kim, Rasmusson, 2004

clc
clear all
close all

[CONSTANTS IC] = CICR_Constants;
simulation_duration = 1e8;
[state algebraic Time]= CICR_CompCore(CONSTANTS, IC, simulation_duration,1);
CICR_visualizeData;
% CICR_initialConditions;
% global TMAX
% TMAX = 1000000; % debugging
% global nAlgebraic;
% global shouldCalculateAlgebraic
% shouldCalculateAlgebraic = false;
% 
% tSpan = [0  TMAX];
% options = odeset('RelTol',1e-6);
% [Time,Y] = ode15s(@(t,y) CICR_func(t,y,CONSTANTS), tSpan, IC, options);
% nAlgebraic = length(Time);
% Ca_i_fig_handle = figure();
% plot(Time, Y(:,14)*1000,'r') % index 14 is Ca_i which is [Ca]i = Cytosolic Ca
% xlabel('Time [ms]')
% ylabel('Ca_i [nM]')
% 
% Ca_JSR_fig_handle = figure();
% plot(Time, Y(:,11)*1000,'b'); %Ca_JSR
% xlabel('Time [ms]')
% ylabel('Ca_JSR [nM]')
% 
% Ca_NSR_fig_handle = figure();
% plot(Time, Y(:,12)*1000,'b'); %Ca_NSR
% xlabel('Time [ms]')
% ylabel('Ca_NSR [nM]')
% 
% 
% % Algebaraic variabes
% shouldCalculateAlgebraic = true;
% [junk algebraic] = CICR_func(Time,Y',CONSTANTS);
% 
% % I_CaL_fig_handle = figure();
% % plot(Time,algebraic(:,1)) % I_CaL (L-type Ca Current)
% % xlabel('Time [ms]')
% % % ylabel('The function $\int f(\theta) d\theta$','FontSize',20,'Interpreter','latex');
% % ylabel('L-type Ca Current  [uA/uF]')
% 
% NCX_Current_fig_handle = figure();
% plot(Time,algebraic(:,2)) % NCX Current'
% xlabel('Time [ms]')
% ylabel('NCX Current  [uA/uF]')
% 
% % PMCA_Current_fig_handle = figure();
% hold on
% plot(Time,algebraic(:,3),'r') % PMCA Current
% xlabel('Time [ms]')
% % ylabel('PMCA Current  [uA/uF]')
% ylabel('[uA/uF]')
% legend('NCX Current','PMCA Current')
% 
% % backgroundCa_Current_fig_handle = figure();
% % plot(Time,algebraic(:,4)) % Background Ca Current
% % xlabel('Time [ms]')
% % ylabel('Background Ca Current  [uA/uF]')
% 
% I_CaT_fig_handle= figure();
% plot(Time,algebraic(:,5)) % I_CaT
% xlabel('Time [ms]')
% ylabel('T-type Ca Current  [uA/uF]')
% 
% J_rel_fig_handle = figure();
% plot(Time,algebraic(:,6)) % J_rel : Release Ca Flux
% xlabel('Time [ms]')
% ylabel('Release Ca Flux  [mol/(s*m^3)]')
% 
% J_up_fig_handle = figure();
% plot(Time,algebraic(:,7)) %  J_up : Uptake Ca Flux
% xlabel('Time [ms]')
% ylabel('Uptake Ca Flux [mol/(s*m^3)]')
% 
% V_m_fig_handle = figure();
% plot(Time,algebraic(:,8)) % V_m - membrane voltage
% xlabel('Time [ms]')
% ylabel('Membrane Voltage [mV]')
% % zoom(1/2)
% 
% % Show [Ca]i figure
% % figure(Ca_i_fig_handle)